package org.project.controller2;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


import org.project.pojo.CityAddress;
import org.project.pojo.Imgs;

import org.project.pojo.Recorddetails;
import org.project.pojo.UR;
import org.project.service.user.ImgsService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Controller
@RequestMapping("/detailspage")
public class Secondcontroller {
   @Resource
	private ImgsService imgsService;
   

   
   

   @RequestMapping("/selectdetails")
   @ResponseBody
  public Recorddetails selectdetails(){
	   
	   HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	   String functionNum=req.getParameter("functionNum");
	//   String functionNum=req.getParameter("functionNum");
	   Recorddetails recorddetails=imgsService.selectdetails(functionNum);
	   
			  
	   
	   
	//   System.out.println(recorddetails);
	   String path=getLoaclURL(req)+"shell//";
	    
	   
	   List<Imgs> list=imgsService.selectdetailimgs(functionNum);
	   List<UR> imglist=new ArrayList<UR>();
	   
	   if(list!=null){
			Iterator<Imgs> it = list.iterator();
			while(it.hasNext()) {
				Imgs imgs=(Imgs)it.next();
				UR ur=new UR();
				ur.setUrl(path+imgs.getImgName());
				
				imglist.add(ur);
			}
			}
	        recorddetails.setImgslist(imglist);  
	       
	 
	        return recorddetails;
	        
	       
  }  
   
   
   
   
   
   
   @RequestMapping("/selectcityshop")
   @ResponseBody
   public List<CityAddress>selectcityshop()  {
	   HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	   
	   
	   String functionNum=req.getParameter("functionNum");
	   String cityName=req.getParameter("cityName");
	   
	  /* System.out.println(functionNum);
	   System.out.println(cityName);*/
	   
	   List<CityAddress> list=null;
		
	   if(functionNum!=null&&cityName!=null){
		   
			CityAddress cityAddress=null;
		//	try {
			/*    cityName = new String(cityName.getBytes("ISO-8859-1"),"UTF-8");*/
		//   System.out.println(cityName);
			    
			    cityAddress=new CityAddress();
			
				cityAddress.setCityName(cityName);
		//	     System.out.println(cityAddress);
				
			/*} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		*/
		     list=imgsService.selectcityshop(cityAddress);	   
		//		System.out.println(list);
		}
		
		   return list;
   }
   
   
   
   
   
   
   

   public static String getLoaclURL(HttpServletRequest request) {
	   
	   String path_now = request.getContextPath();
	   return request.getScheme() + "://" + request.getServerName() + ":"
	   + request.getServerPort() + path_now + "/";
   }

   
   


}
